<?php

namespace Jb\Navigation;

use Jb\Utils\AbstractCollection;

class BreadcrumbsCollection extends AbstractCollection {

    private $pageBreadcrumb;

    public function add(Object $breadCrumb) {
        if(!($breadCrumb instanceof Breadcrumb)) {
            throw new \InvalidArgumentException(get_class($breadCrumb) . ' has to be a Breadcrumb');
        }

        if($breadCrumb->isPage()) {
            $this->pageBreadcrumb = $breadCrumb;
        } else {
            parent::add($breadCrumb);
        }
    }

    public function getLast() {
        return $this->pageBreadcrumb;
    }

}
?>
